package com.example.firstday.kotlin

import kotlinx.coroutines.coroutineScope
import kotlin.contracts.Returns

fun main() {
    println("hello world")
    println(sum(1,2))
    println(sum1(10,20))
    println(sum2(100,200))
    println(list)
    println(list2)
    println(list3)
    var res = simple(1,2 ){ a,b->
        a+b
    }
    var  resTwo = simple(1,2){a,b ->
        a*b
    }
    println("$res  -----  $resTwo")
}
//函数表达式
//求和完整写法
val sum: (Int, Int) -> Int = { a: Int, b: Int -> a + b }
//求和简单写法
val  sum1:(Int,Int)->Int = {a,b->a+b}
val  sum2 = {a:Int,b:Int->a+b}
//map映射 filter过滤 / forEach 纯遍历 / first vs find 找到第一个满足条件的元素
var list = listOf(1, 2, 3, 4, 5)
//var list2 = list.map { a -> a * 2 }
var list2 = list.map { it * 2 }
var list3 = list.filter { it % 2 == 0 }
//var list3 = list.forEach { a ->  println(a) }
var list4 = list.forEach{
    println(it)
}


fun  simple(a:Int ,b:Int ,OP :(Int,Int)->Int):Int{
    return  OP(a,b)
}
fun  simpleTwo(a:Int ,b:Int ,OP :(Int,Int)->Int) = OP(a,b)
